package com.example.leo.mycharmingstudent.a0902;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.leo.mycharmingstudent.R;

/**
 * Created by Leo on 2020/8/31.
 */

public class MyFragment extends Fragment {

    public static final String TITLE = "title";

    public static MyFragment newInstance(String title){
        MyFragment myFragment = new MyFragment();
        Bundle bundle = new Bundle();
        bundle.putString(TITLE,title);
        myFragment.setArguments(bundle);
        return myFragment;
    }

    @Nullable
    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater,
            @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.mine_fragment, null, false);
        Bundle arguments = getArguments();
        String title = null;
        if (arguments != null) {
            title = arguments.getString(TITLE);
        }
        TextView tvTitle = inflate.findViewById(R.id.tv_title_mine_fragment);
        tvTitle.setText(TextUtils.isEmpty(title) ?
                "默认的MineFragment标题" : title);
        //注意，此处一定不要使用默认的代码，return 用自己创建的View
        //如果使用默认的代码，界面空白
//        return super.onCreateView(inflater, container, savedInstanceState);
        return inflate;
    }
}
